﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JoyTalq.Core.Persistence.Ado;
using JoyTalq.Core.Bus.Domain;
using JoyTalq.Core.Persistence.NHibernate;
using JoyTalq.Core.Persistence;
using NHibernate.Criterion;

namespace JoyTalq.Core.Bus.Persistence
{
    public class BusDao : AdoDao, IBusDao
    {
        public INHibernateDao NHibernateDao { get; set; }

        /// <summary>
        /// 取得公車站牌資訊 By 站牌代碼
        /// </summary>
        /// <param name="stopId">站牌代碼</param>
        /// <returns>公車站牌資訊</returns>
        public StopVO GetStopById(string stopId)
        {
            return NHibernateDao.GetVOById<StopVO>(stopId);
        }

        /// <summary>
        /// 取得全部的公車站牌資訊清單
        /// </summary>
        /// <returns>全部的公車站牌資訊清單</returns>
        public IList<StopVO> GetAllStopList()
        {
            return NHibernateDao.GetAllVO<StopVO>();
        }

        /// <summary>
        /// 取得全部的公車站牌資訊清單
        /// </summary>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <returns>全部的公車站牌資訊清單</returns>
        public IList<StopVO> GetAllStopList(int pageIndex, int pageSize)
        {
            return NHibernateDao.GetAllVO<StopVO>(pageIndex, pageSize);
        }

        /// <summary>
        /// 取得全部的公車站牌資訊清單
        /// </summary>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <param name="sortField">排序欄位</param>
        /// <param name="sortDesc">升降冪排序</param>
        /// <returns>全部的公車站牌資訊清單</returns>
        public IList<StopVO> GetAllStopList(int pageIndex, int pageSize, string sortField, bool sortDesc)
        {
            if (sortDesc)
            {
                return NHibernateDao.GetAllVO<StopVO>(pageIndex, pageSize, Order.Desc(sortField));
            }
            else
            {
                return NHibernateDao.GetAllVO<StopVO>(pageIndex, pageSize, Order.Asc(sortField));
            }
        }
    }
}
